package com.frankie.weibo.util.image;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.frankie.weibo.R;
import com.nostra13.universalimageloader.core.DefaultConfigurationFactory;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Frankie on 2016/8/18.
 */

public class ImageLoadUtil {

    public static void loadCommonImage(String url, ImageView imageView){
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(url, imageView, getOptions(false));
    }

    public static void loadCircleImage(String url, ImageView imageView){
        ImageLoader imageLoader = ImageLoader.getInstance();
        DisplayImageOptions options = getOptions(true);
        imageLoader.displayImage(url, imageView, options);
    }

    private static final DisplayImageOptions getOptions(boolean circle){
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_loading)
                .showImageForEmptyUri(R.drawable.ic_loading)
                .showImageOnFail(R.drawable.ic_loading)
                .cacheInMemory(true)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true)
                .considerExifParams(false)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(circle ? new CircleBitmapDisplayer() : DefaultConfigurationFactory.createBitmapDisplayer())
                .build();
        return options;
    }

}
